﻿using dreamwork.membercenter.api.Model.Data;
using Dreamwork.Core.Infrastructure.Mongodb;
using System.Linq;
using System.Threading.Tasks;

namespace dreamwork.membercenter.api.Services
{
	public class MemberCenterService : IMemberCenterService
	{
		private readonly IMongoRepository<MemberUser> _memberUser;
		private readonly IMongoRepository<SomethingOfUser> _somethingOfUserRepository;
		public MemberCenterService(
			IMongoRepository<SomethingOfUser> somethingOfUserRepository,
			IMongoRepository<MemberUser> memberUser
			)
		{
			_somethingOfUserRepository = somethingOfUserRepository;
			_memberUser = memberUser;
		}

		public async Task AddUserAsync()
		{
			await _memberUser.AddAsync(new MemberUser() { Name = "Jerry" });
		}
		public async Task<MemberUser> GetUserAsync()
		{
			var items = await _memberUser.GetAllAsync();
			return items.FirstOrDefault();
		}
		public async Task UpdateUserAsync(MemberUser model)
		{
			await _memberUser.UpdateAsync(model);
		}


		public async Task AddSomethingAsync()
		{
			await _somethingOfUserRepository.AddAsync(new SomethingOfUser() { Content = "Jerry" });
		}
		public async Task<SomethingOfUser> GetSomethingAsync()
		{
			var items = await _somethingOfUserRepository.GetAllAsync();
			return items.FirstOrDefault();
		}
		public async Task UpdateSomethingAsync(SomethingOfUser model)
		{
			await _somethingOfUserRepository.UpdateAsync(model);
		}

	}
}
